package guhong.play.commandsystem.gui.key.system;

import guhong.play.commandsystem.CommandManager;
import guhong.play.commandsystem.gui.key.KeyListenerHandler;
import guhong.play.commandsystem.gui.ui.UIManger;
import guhong.play.commandsystem.history.CommandHistoryManager;
import lombok.Data;

import java.awt.event.KeyEvent;

/**
 * ↓ 方向键监听
 * @author : 李双凯
 * @date : 2019-11-20 22:32
 **/
@Data
public class DownHandler implements KeyListenerHandler {

    /**
     * 是否监听
     *
     * @param e 事件对象
     * @return 监听返回true
     */
    @Override
    public boolean isListener(KeyEvent e) {
        return e.getKeyCode() == KeyEvent.VK_DOWN;
    }


    /**
     * 执行
     *
     */
    @Override
    public void execute() {
        CommandHistoryManager historyCommandManage = CommandManager.getCommandHistoryManager();
        UIManger uiManger = CommandManager.getUiManger();

        uiManger.clearCommand();
        uiManger.input(historyCommandManage.next());
    }
}
